package demo.aspect.aj;

import demo.model.UserAccount;


public aspect UserAccountAspect {

    pointcut callPay(int amount, UserAccount account):
                call(boolean demo.model.UserAccount.pay(int)) && args(amount) && target(account);

        before(int amount, UserAccount account): callPay(amount, account) {
            System.out.println("[UserAccountAspect]付款前总金额: " + account.balance);
            System.out.println("[UserAccountAspect]需要付款: " + amount);
        }

        boolean around(int amount, UserAccount account): callPay(amount, account) {
            if (account.balance < amount) {
                System.out.println("[UserAccountAspect]拒绝付款!");
                return false;
            }
            return proceed(amount, account);
        }

        after(int amount, UserAccount balance): callPay(amount, balance) {
            System.out.println("[UserAccountAspect]付款后，剩余：" + balance.balance);
        }
}